package com.ddwl.wallet.converter;

import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.ddwl.common.constant.WalletEnum;

/**
 * @Author hemiaojun
 * @Date 2021/7/7 11:41
 */
public class ChannelTypeConverter implements Converter<Integer> {

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        return null;
    }

    @Override
    public CellData convertToExcelData(Integer typeKey, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        String typeVal = getName(typeKey);
        return new CellData(StrUtil.isEmpty(typeVal) ? "":typeVal);
    }

    private String getName(Integer code){
        WalletEnum.WithdrawChannelEnum[] values = WalletEnum.WithdrawChannelEnum.values();
        for (WalletEnum.WithdrawChannelEnum channelEnum : values) {
            if (code.equals(channelEnum.getCode())) {
                return channelEnum.getName();
            }
        }
        return null;
    }

}
